#!/usr/bin/env bash
set -e

ask() {
  # http://djm.me/ask
  while true; do

    if [ "${2:-}" = "Y" ]; then
      prompt="Y/n"
      default=Y
    elif [ "${2:-}" = "N" ]; then
      prompt="y/N"
      default=N
    else
      prompt="y/n"
      default=
    fi

    # Ask the question
    read -p "$1 [$prompt] " REPLY

    # Default?
    if [ -z "$REPLY" ]; then
       REPLY=$default
    fi

    # Check if the reply is valid
    case "$REPLY" in
      Y*|y*) return 0 ;;
      N*|n*) return 1 ;;
    esac

  done
}

dir=`pwd`
if [ ! -e "${dir}/${0}" ]; then
  echo "Script not called from within repository directory. Aborting."
  exit 2
fi
dir="${dir}/.."


ask "Install packages(Trisquel)?" N && bash ./dependencies-trisquel

ask "Install symlink for zsh?" Y && stow --no-folding -d ${dir} zsh -t ~/ 
ask "Install symlink for i3?" Y &&  stow --no-folding -d ${dir} i3 -t ~/
ask "Install symlink for vim?" Y &&  stow --no-folding -d ${dir} vim -t ~/
ask "Install symlink for mpd?" Y &&  stow --no-folding -d ${dir} mpd -t ~/
ask "Install symlink for ncmpcpp?" Y &&  stow --no-folding -d ${dir} ncmpcpp -t ~/
ask "Install symlink for mimeapps?" Y &&  stow --no-folding -d ${dir} mimeapps -t ~/
ask "Install symlink for .gitconfig/git_prompt.zsh?" Y &&  stow --no-folding -d ${dir} git -t ~/

